package com.platform.qujia.controller;

import com.alibaba.fastjson.JSON;
import com.platform.qujia.pojo.vo.YunHuaParamsVO;
import com.platform.qujia.service.YunHuaBizService;
import com.platform.qujia.utils.ResultData;
import com.platform.qujia.utils.StringUtils;
import com.platform.qujia.utils.exception.CustomException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/yunHuaBiz")
@Api(tags = "对接云化相关接口")
@Slf4j
public class YunHuaBizController {

    @Resource
    private YunHuaBizService yunHuaBizService;

    @Value("${qujia.yunHuaH5Url}")
    private String yunHuaH5Url;


    @ApiImplicitParams({
            @ApiImplicitParam(name="stationId",value="油站Id",required=true),
            @ApiImplicitParam(name="mobilePhone",value="手机号",required=true),
    })
    @GetMapping("/getYunHuaParams")
    public ResultData getYunHuaParams(@RequestParam String enterpriseId, @RequestParam String mobilePhone){
        log.info("获取跳转小Ai H5需要的信息,enterpriseId【{}】,mobilePhone【{}】",enterpriseId, mobilePhone);
        if(StringUtils.isEmpty(mobilePhone) || StringUtils.isEmpty(enterpriseId)){
            throw new CustomException("缺少参数！");
        }
        YunHuaParamsVO yunHuaParams = yunHuaBizService.getYunHuaParams(enterpriseId, mobilePhone);

        String url = yunHuaH5Url + "/#/?platformId=" + yunHuaParams.getPlatformId() + "&params=" +
                yunHuaParams.getParams();
        log.info("跳转小ai加油H5：【{}】", url);
        return ResultData.success(url);
    }

}
